package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@Api(value ="用户购物车")
@RequestMapping("/user/shoppingCart")
public class UserShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    @ApiOperation(value = "获取购物车列表")
    public Result shoppingCartList() {
        List<ShoppingCart> cart = shoppingCartService.getShoppingCartList();
        return Result.success(cart);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @PostMapping("/sub")
    @ApiOperation(value = "删除购物车的一个商品")
    public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        Integer integer = shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车商品")
    public Result deleteShoppingCart() {
            shoppingCartService.deleteShoppingCart();
        return Result.success();
    }



}